<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});

Route::group(['namespace' => "Api"], function () {

    Route::get('/test','TestController@index');
    //login
    Route::group(['prefix' => 'auth'], function () {
        Route::post('/login', 'AuthController@login');
        Route::post('/get_phone','AuthController@getPhoneNumber');
    });

    Route::group(['prefix' => "city"], function () {
        Route::get('/data', "CityController@index");
    });
    Route::group(['prefix' => 'carousel'], function () {
        Route::get('/', "CarouselController@index");
    });
    Route::group(['prefix' => 'goods'], function () {
        Route::get('/', 'GoodsController@index');
        Route::get('/{id}', 'GoodsController@show');
    });
    Route::resource('spec', 'SpecController');
    Route::resource('news', 'NewsController');
    Route::resource("group_buy", 'GroupBuyController');

    Route::group(['middleware' => ['auth:api']], function () {
        Route::post('cart/update_checked', 'CartController@updateChecked');
        Route::resource("cart", "CartController");

        Route::get('address/get_default', 'AddressController@get_default');
        Route::resource('address', 'AddressController');

        Route::resource("order", "OrderController");
        Route::post('/order/express','OrderController@express');
        Route::post('/order/check_money','OrderController@check_money');
        //确认订单
        Route::post('/order/confirm_order', 'OrderController@confirmOrder');
        Route::get('/user/group_buy', 'UserController@group_buy');
        Route::get('/group_master/recent','GroupMasterController@recent_group_buy');
        Route::get('/user/group_master/{id}', 'GroupMasterController@user_group');
        Route::get('/group_master/{id}','GroupMasterController@show');

        Route::post('/upload', 'UploadController@index');
        Route::resource("comment", 'CommentController');

        Route::resource("merchant","MerchantController");

        Route::get('commission','CommissionController@index');
        Route::post('commission/withdraw','CommissionController@withdraw');
        Route::get('commission/withdraw_list','CommissionController@withdraw_list');
        Route::get('commission/query_withdraw','CommissionController@query_withdraw');
        Route::get('commission/cms','CommissionController@commission_cms');
        Route::get('user_coupon','UserCouponController@index');
        //用户海报
        Route::get('poster','UserController@poster');


        Route::resource("address", "AddressController");


        Route::post("/pay", "PayController@index");
        Route::get("/pay/query/{order_number}", "PayController@queryPay");
        Route::get("/share",'ShareController@index');


    });

    Route::any('/pay/notify', "PayController@notify");



});

//后台
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function (\Illuminate\Routing\Router $router) {
    $router->post('/login', 'AuthController@login');
    $router->post('/register', 'AuthController@register');
    $router->post('/upload', 'UploadController@index');
//'jwt.role:admin', 'auth:admin'
    $router->group(['middleware' => ['auth:admin']], function () use ($router) {
        $router->resource('carousel', 'CarouselController');
        $router->resource('goods', 'GoodsController');
        $router->get('order/cms',"OrderController@cms");
        $router->get('order/export',"OrderController@export");
        $router->resource('order', 'OrderController');
        $router->put('order_detail/{id}','OrderDetailController@update');
        $router->resource('goods_type', 'GoodsTypeController');
        $router->resource('news', 'NewsController');
        $router->resource('spec', 'SpecController');
        $router->resource('users', 'UserController');
        $router->resource('group_buy', 'GroupBuyController');
        $router->resource('category', 'CategoryController');
        $router->get('group_master', 'GroupMasterController@index');
        $router->post("delivery",'OrderController@delivery');

        $router->get('merchant/export',"CommissionController@export");
        $router->resource('merchant','MerchantController');
        $router->get('sku','SkuController@index');
        $router->post('user_coupon','UserCouponController@store');
        $router->resource('coupon','CouponController');
        $router->resource('store','StoreController');


    });

});
